#include "deletebuttondelegate.h"

#include "ElaPushButton.h"

DeleteButtonDelegate::DeleteButtonDelegate(QObject *parent)
    : QStyledItemDelegate(parent) {}

QWidget *DeleteButtonDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const {
    ElaPushButton *button = new ElaPushButton("删除", parent);
    connect(button, &ElaPushButton::clicked, [this, index]() {

        emit deleteRowRequested(index.row()); // 发射信号通知删除行
    });
    // connect(button, &QPushButton::clicked, [this, index]() {
    //     QPointer<DeleteButtonDelegate> safeThis(this);
    //     if (safeThis) {
    //         emit safeThis->deleteRequested(index.row());
    //     }
    // });
    return button;
}

void DeleteButtonDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const {
    editor->setGeometry(option.rect);
}
